//
//  SettingsViewController.m
//  CareWithFriends
//
//  Created by Versatile Systems, Inc on 11/18/13.
//  Copyright (c) 2013 Muludiang. All rights reserved.
//

#import "SettingsViewController.h"
#import "CWFData.h"
#import "FollowingViewController.h"

@interface SettingsViewController ()

@end

@implementation SettingsViewController

@synthesize settingsTable;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // return number of rows
    return 2;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    CWFData *dataObj = [CWFData sharedInstance];
    /*if (indexPath.row == 0){
        [cell.textLabel setText:@"Email Notifications"];
        UISwitch *emailSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
        cell.accessoryView = emailSwitch;
    }else if (indexPath.row == 1){
        [cell.textLabel setText:@"Show my status to others"];
        UISwitch *statusSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
        cell.accessoryView = statusSwitch;
    }else if (indexPath.row == 2){
        [cell.textLabel setText:[NSString stringWithFormat:@"People I'm Following (%d)",
                                 [[dataObj.getFollowedUsers valueForKey:@"users"] count]
                                 ]
         ];
        if ([[dataObj.getFollowedUsers valueForKey:@"users"] count] > 0){
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        }
    } else {
        [cell.textLabel setText:[NSString stringWithFormat:@"People Following Me (%d)",
                                 [[dataObj.getUserFollowers valueForKey:@"users"] count]
                                 ]
         ];
        if ([[dataObj.getUserFollowers valueForKey:@"users"] count] >> 0){
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        }
    }*/
    
    if (indexPath.row == 0){
        [cell.textLabel setText:[NSString stringWithFormat:@"People I'm Following (%d)",
                                 [[dataObj.getFollowedUsers valueForKey:@"users"] count]
                                 ]
         ];
        if ([[dataObj.getFollowedUsers valueForKey:@"users"] count] > 0){
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        }
    } else {
        [cell.textLabel setText:[NSString stringWithFormat:@"People Following Me (%d)",
                                 [[dataObj.getUserFollowers valueForKey:@"users"] count]
                                 ]
         ];
        //if ([[dataObj.getUserFollowers valueForKey:@"users"] count] > 0){
        //    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        //}
    }
    
    return cell;
    
}


-(IBAction)logout:(id)sender{
    UIAlertView *logoutAlert = [[UIAlertView alloc] initWithTitle:Nil message:@"Are you sure you want to log out?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
    [logoutAlert show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1 ){
    [self.navigationController popToRootViewControllerAnimated:YES];
        CWFData *dataObj = [CWFData sharedInstance];
        dataObj.currentRequest = [NSString stringWithFormat:@"notAuthenticated"];
        dataObj.CWFAuthtoken = @"authNotAttempted";
        [dataObj CWFLogout];
        [self dismissViewControllerAnimated:YES completion:nil];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0){
    FollowingViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"following_view"];
    [self.navigationController pushViewController:dvc animated:YES];
    }
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
